package cn.wolfcode.wms.web.controller;

import cn.wolfcode.wms.page.PageResult;
import cn.wolfcode.wms.query.QueryObject;
import cn.wolfcode.wms.service.IPermissionService;
import cn.wolfcode.wms.vo.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("permission")
public class PermissionController {
    @Autowired
    private IPermissionService service;

    @RequestMapping("list")
    public String list(Map map, QueryObject qo) {
        PageResult pageResult = service.query(qo);
        map.put("pageResult", pageResult);
        return "permission/list";
    }

    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id) {
        if (id != null) {
            try {
                service.delete(id);
            } catch (Exception e) {
                return JSONResult.mark(e.getMessage());
            }
        }
        return JSONResult.success("删除成功");
    }

    @RequestMapping("reload")
    @ResponseBody
    public JSONResult reload() {
        try {
            service.reload();
        }catch (Exception e){
            return JSONResult.mark(e.getMessage());
        }
        return JSONResult.success("加载成功");
    }
}
